package cn.com.cetccst.appstore.jssdk;

import android.content.Context;

import com.google.gson.annotations.SerializedName;

import cn.com.cetccst.appstore.jssdk.viewmodel.JSSDKViewModel;
import cn.com.cetccst.appstore.tools.Utils;
import cn.com.cetccst.sdk.modelbase.BaseResp;


public class ActionGetCanUse extends BaseJSAction<ActionGetCanUse.RequestPara, BaseResp> {
    public static final String ACTION = "getCanIUse";

    private String[] apiNames = new String[]{
            ActionDownloadFile.ACTION,
            ActionCancelDownloadFile.ACTION,
    };

    private String[] listenerNames = new String[]{
            JSSDKViewModel.LISTENER_LOCATION_CHANGED,
            JSSDKViewModel.LISTENER_LIFECYCLE_SHOW,
            JSSDKViewModel.LISTENER_LIFECYCLE_HIDE,
    };

    ActionGetCanUse(Context context, CXApiImplInnerApp icxapi, String parameters) {
        super(context, icxapi, parameters);
    }

    @Override
    public void handleAction(Response response) {
        response.setRespJson(buildSuccessResp(null));
    }

    @Override
    protected RequestPara parserParameters(String para) {
        return Utils.getGson().fromJson(para, RequestPara.class);
    }

    @Override
    protected String buildSuccessResp(BaseResp icxResp) {
        Resp<RespData> resp = new Resp();
        resp.code = 0;
        resp.data = new RespData();
        resp.data.apiNames = apiNames;
        resp.data.listenerNames = listenerNames;
        resp.data.versionCode = ActionGetContextParams.JSSDK_VERSION_CODE;
        return Utils.getGson().toJson(resp);
    }

    static class RequestPara {
        @SerializedName("appKey")
        String appKey;
    }

    static class RespData {
        @SerializedName("apiNames")
        public String[] apiNames;
        @SerializedName("listenerNames")
        public String[] listenerNames;
        @SerializedName("versionCode")
        public int versionCode;
    }
}
